// pages/frontSdt/frontSdt.js
var api = require('../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    studentList: [],
    studentDetail:[],
    modalHidden:true,
  },

  cancel: function () {
    this.setData({
      modalHidden: true
    });
  },
  confirm: function () {
    wx.navigateTo({
      url: '../frontFee/frontFee?studentDetail=' + JSON.stringify(this.data.studentDetail1)
    })
  },

//单选按钮事件
  radioChange(e){
    var id = e.detail.value;
    var studentDetail1 =this.data.studentDetail.filter(item=>{
      return item.id==id
    })

    this.setData({
      studentDetail1
    })
  },

  //跳转续费页面
  toFee(e) {
    var studentId = e.currentTarget.dataset.id;
    this.setData({
      studentId
    })
    api.fetchApi('reception/student_detail', { token: wx.getStorageSync('token'), id: this.data.studentId }).then(res => {
      this.setData({
        studentDetail:res
      })
      if (res.length == 1) {
        wx.navigateTo({
          url: '../frontFee/frontFee?studentDetail=' + JSON.stringify(this.data.studentDetail)
        })
      }else{
        this.setData({
          modalHidden:false
        });
      }
    })
   
   
  },

  //新增学生
  addStudent() {
    wx.navigateTo({
      url: '../addStudent/addStudent',
    })
  },
  //学生搜索字段
  seachName(e) {
    console.log(e.detail.value)
    this.setData({
      search: e.detail.value
    })

    this.setData({
      studentList:[]
    })

    
      this.getStudentList(1)
    
    
  },

  //获取学生管理列表
  getStudentList(page) {
    api.fetchApi('reception/student_management', { token: wx.getStorageSync('token'), page, search: this.data.search }).then(res => {
      var studentList = this.data.studentList,
        studentList1 = res.data;
      if (studentList1.length == 0 && page > 1) {
        //api.showToast('到底啦!', 'http://qnwmfx.laigl.com/iconimg/warn.png', 1500)
        this.setData({
          isMore: true
        })
        return
      }
      studentList = [...studentList, ...studentList1]
      this.setData({
        studentList,
        page,
        count: res.count
      })
    })
  },

  //点击拨打电话
  phoneCall(e) {
    //console.log(e.currentTarget.dataset.phone)
    var phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getStudentList(1)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
this.setData({
  studentList:[]
})
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var page = this.data.page || 1;
    page++;
console.log(page)
    this.getStudentList(page)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})